package com.rising.face.lock.synchronize;

/**
 * @Author: rising
 * @Description:
 * @Date: create in 2021/1/10 19:12
 */
public class DeadLockThread implements Runnable{
    private String lockA;
    private String lockB;

    public DeadLockThread() {

    }

    public DeadLockThread(String lockA, String lockB) {
        this.lockA = lockA;
        this.lockB = lockB;
    }

    @Override
    public void run() {
        synchronized (lockA) {
            System.out.println(Thread.currentThread().getName() + "\t自己持有：" + lockA + "\t尝试获得：" + lockB);
            try {
                Thread.sleep(2 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            synchronized (lockB) {
                System.out.println(Thread.currentThread().getName() + "\t自己持有：" + lockB + "\t尝试获得：" + lockA);
            }

        }
    }

}
